function headerScroll(h) {
    height = h || 80;
    var scT = 0;


    function setNav() {
        scT = $(window).scrollTop();
        if (scT < height) {
            $(".nav-fixed-top").removeClass("nav-fixed-bg");
        } else {
            $(".nav-fixed-top").addClass("nav-fixed-bg");
        }
    }

    setNav();
    headerMediaDropDown();

    $(window).on("scroll", function() {
        setNav()
    });
}

function navWorthSrop() {
    $(".dropdown-worth-d-line-main").mouseenter(function(e) {
        $(e.target).parents(".dropdown-worth-d-line").addClass("focus")
    })
    $(".dropdown-worth-d-line-main").mouseleave(function(e) {
        $(e.target).parents(".dropdown-worth-d-line").removeClass("focus")
    })
}

function headerMediaDropDown() {
    $(".drop-media-left-span").mouseenter(function() {
        const _this = this;
        $(_this).addClass("active").siblings().removeClass("active");
        $(".drop-media-content-ibox").removeClass("active").eq($(_this).index()).addClass("active");
    })
}

function slideBarTrans() {
    $("#asideBar > .aside-div").mouseover(function() {
        $(this).find(".details").css({
            "width": "180px"
        })
    });
    $("#asideBar > .aside-div").mouseleave(function() {
        $(this).find(".details").css({
            "width": "0"
        })
    });
}

function countTime(dom, time) {
    dom = dom || "#countTime";
    time = time || new Date();
    //获取当前时间  
    var date = new Date();
    var now = date.getTime();
    //设置截止时间  
    var str = new Date(time).getTime() + 365 * 24 * 60 * 60 * 1000;
    var endDate = new Date(str);
    var end = endDate.getTime();

    //时间差  
    var leftTime = end - now;
    //定义变量 d,h,m,s保存倒计时的时间  
    var d, h, m, s;
    if (leftTime >= 0) {
        d = Math.floor(leftTime / 1000 / 60 / 60 / 24) == 0 ? "" : Math.floor(leftTime / 1000 / 60 / 60 / 24) + "天";
        h = Math.floor(leftTime / 1000 / 60 / 60 % 24) == 0 ? "" : Math.floor(leftTime / 1000 / 60 / 60 % 24) + "时";
        m = Math.floor(leftTime / 1000 / 60 % 60) == 0 ? "" : Math.floor(leftTime / 1000 / 60 % 60) + "分";
        s = Math.floor(leftTime / 1000 % 60) == 0 ? "" : Math.floor(leftTime / 1000 % 60) + "秒";
    }
    $(dom).html(d + h + m + s)

    //递归每秒调用countTime方法，显示动态时间效果  
    setTimeout(function() {
        countTime(dom, time)
    }, 1000);

}

// window.open
$(document).on("click", "[data-href]", function() {
    const href = $(this).attr("data-href");
    window.open(href);
})

function getDateDiff(dateStr) {
    var
        d_seconds,
        d_minutes,
        d_hours,
        d_days,
        timeNow = parseInt(new Date().getTime() / 1000),
        d,

        date = new Date(dateStr),
        Y = date.getFullYear(),
        M = date.getMonth() + 1,
        D = date.getDate(),
        H = date.getHours(),
        m = date.getMinutes(),
        s = date.getSeconds();
    if (M < 10) {
        M = '0' + M;
    }
    if (D < 10) {
        D = '0' + D;
    }
    if (H < 10) {
        H = '0' + H;
    }
    if (m < 10) {
        m = '0' + m;
    }
    if (s < 10) {
        s = '0' + s;
    }

    d = timeNow - (date / 1000);
    d_days = parseInt(d / 86400);
    d_hours = parseInt(d / 3600);
    d_minutes = parseInt(d / 60);
    d_seconds = parseInt(d);
    if (d_days > 0 && d_days < 10) {
        return d_days + '天前';
    } else if (d_days <= 0 && d_hours > 0) {
        return d_hours + '小时前';
    } else if (d_hours <= 0 && d_minutes > 0) {
        return d_minutes + '分钟前';
    } else if (d_seconds < 60) {
        if (d_seconds <= 0) {
            return '刚刚';
        } else {
            return d_seconds + '秒前';
        }
    } else if (d_days >= 3 && d_days < 30) {
        return M + '-' + D + ' ' + H + ':' + m;
    } else if (d_days >= 30) {
        return Y + '-' + M + '-' + D + ' ' + H + ':' + m;
    }
}

function drawMain(drawing_elem, percent, lineWidth, forecolor, bgcolor) {
    /*
        @drawing_elem: 绘制对象
        @percent：绘制圆环百分比, 范围[0, 100]
        @forecolor: 绘制圆环的前景色，颜色代码
        @bgcolor: 绘制圆环的背景色，颜色代码
    */
    var context = drawing_elem.getContext("2d");
    var center_x = drawing_elem.width / 2;
    var center_y = drawing_elem.height / 2;
    var rad = Math.PI * 2 / 100;
    var speed = 0;
    var lineWidth = lineWidth || 40;

    // 绘制背景圆圈
    function backgroundCircle() {
        context.beginPath();
        context.lineWidth = lineWidth;
        var radius = center_x - lineWidth;
        context.strokeStyle = bgcolor;
        context.arc(center_x, center_y, radius, 0, Math.PI * 2);
        context.stroke();
    }

    //绘制运动圆环
    function foregroundCircle(n) {
        context.strokeStyle = forecolor;
        var radius = center_x - lineWidth;
        context.beginPath();
        context.arc(center_x, center_y, radius, -Math.PI / 2, -Math.PI / 2 + n * rad, false); //用于绘制圆弧context.arc(x坐标，y坐标，半径，起始角度，终止角度，顺时针/逆时针)
        context.stroke();
    }


    // backgroundCircle();
    // foregroundCircle(percent);

    // 执行动画
    (function drawFrame() {
        if (speed <= percent) {
            window.requestAnimationFrame(drawFrame)
        } else {
            return false
        }
        context.clearRect(0, 0, drawing_elem.width, drawing_elem.height)
        backgroundCircle()
        // text(speed)
        foregroundCircle(speed)
        if (speed <= percent) {
            speed++
        } else {
            return false;
        }
    })()
}

function ImgGallery(swiperHtl) {
    // layer.photos({
    //     photos: '#pdfCont'
    //     ,anim: 5
    // }); 

    // let swiperHtl=`<div class="swiper"><div class="swiper-wrapper">`
    // $("#pdfCont").find("img").each((i,j)=>{swiperHtl+=`<div class="swiper-slide">${$(j).prop("outerHTML")}</div>`})
    // swiperHtl+=`</div> <div class="swiper-button-prev swiper-button-white"></div><div class="swiper-button-next swiper-button-white"></div></div>`

    $(document).on("click", "#pdfCont img", function() {
        const Imgindex = $(this).index();
        const lidx = layer.open({
            content: swiperHtl,
            skin: "pdfCongLy",
            title: false,
            btn: false,
            area: ['100vw', '100vh'],
            closeBtn: 1,
            shade: [0.8, '#000'],
            shadeClose: !0,
            success: function() {
                new Swiper('.swiper', {
                    initialSlide: Imgindex,
                    navigation: {
                        nextEl: '.swiper-button-next',
                        prevEl: '.swiper-button-prev',
                    },
                });
                $(".swiper-slide ").click(function(e) {
                    if (e.target.nodeName == "DIV") {
                        layer.close(lidx);
                    }
                })
            }
        });
    })

}

$(document).on("click", ".btn-ly-ask", function() {

    winWide = window.innerWidth;
    const source = $(this).attr("data-source");
    let area = null;

    if (winWide <= 960) { //960及以下分辨率
        area = ['100%', '100%']
    } else {
        area = ['800px', '536px']
    }

    layer.open({

        type: 1,
        title: '申请提交后，我们会尽快与您联系',
        skin: 'larg-form-skin',
        shadeClose: true,
        content: `
        <div id="alert-form">
            <div class="cooperate-main-form-cont">
                <form action="" class="form" id="form-user">
                    <input type="hidden" name="source" value="${source}">
                    <div class="cooperate-main-item-title">
                        公司信息
                    </div>
                    <div class="cooperate-ipt-group">
                        <div class="form-l-group">
                            公司名称
                        </div>
                        <div class="form-group">
                            <input type="text" id="company" name="company" data-rule="required" data-msg="请输入公司名称全称" placeholder="请输入公司名称全称" class="form-control">
                        </div>
                    </div>
                    <div class="cooperate-ipt-group">
                        <div class="form-l-group">
                            所在城市
                        </div>
                        <div class="form-group city-picker-cont" style="position:relative;">
                            <input readonly type="text" data-toggle="city-picker" id="city" name="city" class="form-control">
                        </div>
                    </div>
                    <div class="cooperate-ipt-group">
                        <div class="form-l-group">
                            办公地址
                        </div>
                        <div class="form-group">
                            <input type="text" id="address" name="address" data-rule="required" data-msg="请输入办公地址" placeholder="请输入办公地址" class="form-control">
                        </div>
                    </div>
                    <div class="cooperate-pc-line">
                        <div class="cooperate-ipt-group">
                            <div class="form-l-group">
                                公司规模
                            </div>
                            <div class="form-group">
                                <select class="form-control" id="sacle" name="sacle">
                                    <option value="0" selected>未知</option>
                                    <option value="1">1-10人</option>
                                    <option value="2">10-99人</option>
                                    <option value="3">100-500人</option>
                                    <option value="4">500人以上</option>
                                </select>
                            </div>
                        </div>
                        <div class="cooperate-ipt-group">
                            <div class="form-l-group">
                                年营销费用
                            </div>
                            <div class="form-group">
                                <select class="form-control" id="sales" name="sales">
                                    <option value="0" selected>未知</option>
                                    <option value="1">50万以下</option>
                                    <option value="2">50-100万</option>
                                    <option value="3">100万-500万</option>
                                    <option value="3">500万以上</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="cooperate-main-item-title">
                        合作联系人
                    </div>
                    <div class="cooperate-pc-line cooperate-pc2-line">
                        <div class="cooperate-ipt-group">
                            <div class="form-l-group">
                                公司名称
                            </div>
                            <div class="form-group">
                                <input type="text" id="username" name="username" data-rule="required" data-msg="请输入联系人姓名" placeholder="请输入联系人姓名" class="form-control">
                            </div>
                        </div>
                        <div class="cooperate-ipt-group">
                            <div class="form-l-group">
                                公司名称
                            </div>
                            <div class="form-group">
                                <input type="text" id="job" name="job" data-rule="required" data-msg="请输入联系人职务" placeholder="请输入联系人职务" class="form-control">
                            </div>
                        </div>
                        <div class="cooperate-ipt-group">
                            <div class="form-l-group">
                                公司名称
                            </div>
                            <div class="form-group">
                                <input type="text" id="phone" name="phone" data-rule="required" data-msg="请输入联系人手机" placeholder="请输入联系人手机" class="form-control">
                            </div>
                        </div>
                    </div>
                    <button type="submit" class="btn btn-theme btn-login">提交</button>
                </form>
            </div>
        </div>`,
        area: area,

        success: function(l, index) {

            $('#city').citypicker({
                province: "北京市",
                city: "北京市",
                district: "东城区"
            });



            $('#form-user').validator({

                timely: 2,
                valid: function(form) {
                    // $.post("http://a.iqianfeng.com/api/index/user_submit", $(form).serialize())
                    //     .done(function (r) {
                    //         if (r.code) {
                    //             $('#form-user').trigger("reset")
                    //             layer.msg('提交成功', {
                    //                 icon: 1,
                    //             });
                    //             layer.close(index);
                    //         } else {
                    //             layer.msg(r.msg, {
                    //                 icon: 2,
                    //             });
                    //         }
                    //     });
                    $.ajax({
                        type: "post",
                        async: false,
                        dataType: "jsonp",
                        jsonp: "callback",
                        url: "https://a.iqianfeng.com/api/index/user_submit",
                        data: $(form).serialize(),
                        success: function(r) {
                            if (r.code) {
                                $('#form-user').trigger("reset")
                                layer.msg('提交成功', {
                                    icon: 1,
                                });
                                layer.close(index);
                            } else {
                                layer.msg(r.msg, {
                                    icon: 2,
                                });
                            }
                        }
                    })
                }
            });
        }
    });

})

$(document).on("click", ".btn-ly-tidio", function() {
    // $("#tidio-chat-iframe").contents().find("#button-body").trigger("click");
    $("#newBridge .nb-icon-groups .nb-icon-groups-item").eq(4).trigger("click");
    $("#newBridge #nb_icon_wrap").trigger("click");
})



$(function() {
    slideBarTrans()
    // $("#header .manage-link").click(function(){
    //     localStorage.removeItem("loginUrl");
    // });

})




// mob

$(document).on("click", ".nav-fixed-top .icon.more", function() {
    $(".navbar-mask").addClass("open")
})
$(document).on("click", ".nav-fixed-top .navbar-mask", function(e) {
    if ($(e.target).hasClass("navbar-mask")) {
        $(".navbar-mask").removeClass("open")
    }
})
$(document).on("click", ".com_header_collapse_list", function(e) {
    $(this).parent("li").toggleClass("open").siblings().removeClass("open");
});





// 增加 认证 2205 临时
$(document).on("click", "span[data-href]", function() {
    window.open($(this).attr("data-href"), "_blank")
})



//temp 618
if (new Date().getTime() < 1655568000000) {
    $("#side-618").show()
}



//全局黑色提示
$(document).on('mouseenter mouseleave', '[data-tip-value]', function(e) {
    if (e.type === 'mouseenter') {
        // console.log(e)
        // var pos = $(this).offset(),
        var pos = {
                top: e.clientY,
                left: e.clientX
            },
            _w = $(this).width(),
            title = $(this).attr("data-tip-value"),
            _xy = $(this).data('xy') || {
                x: 0,
                y: 0
            };
        // $("#tool_tips").html(title).css({
        // 	top: pos.top - 6 + _xy.y,
        // 	left: pos.left + 6 + _w + _xy.x
        // }).show();
        $("#tool_tips").html(title).css({
            top: pos.top,
            left: pos.left
        }).show();

    } else if (e.type === 'mouseleave') {
        $("#tool_tips").html("").hide();
    }
});


function getSearchStr(name) {
    let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    let r = decodeURI(window.location.search.substr(1)).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

// 推广  20221018
if (getSearchStr("bd_vid")) {
    $(document).on("click", "[data-bd_yx='ty1']", function() {
        $.get("https://www.iqianfeng.com/baiduapi.php?logidUrl=" + location.origin + location.pathname + "?bd_vid=" + getSearchStr("bd_vid"));
    })
}